﻿package mortal.game.view.mainUI.rightTop
{
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;

    public class RightTopBar extends GSprite
    {
        private var _bntRank:GLoadedButton;
        private var _btnMarket:GLoadedButton;
        private var _bntLoginNotice:GLoadedButton;
        private var _bntAchievement1:GLoadedButton;
        private var _signUp:GLoadedButton;
        private var _netWork:NetWorkStatePanel;
        private var _line2:Array;
        private var _levelOpenObj2:Object;
        private var iconWidth:int = 44;
        private var iconHeight:int = 43;

        public function RightTopBar()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bntRank = UIFactory.gLoadedButton(ImagesConst.rt_rank_upSkin, this.iconWidth * 2 - 82, 0, 118, 47, this);
            this._btnMarket = UIFactory.gLoadedButton(ImagesConst.rt_market_upSkin, this.iconWidth * 1, this.iconHeight * 1, 42, 42, this);
            this._btnMarket.name = "btnMarket";
            this._bntLoginNotice = UIFactory.gLoadedButton(ImagesConst.updateNotice_upSkin, this.iconWidth * 0, this.iconHeight * 1, 42, 42, this);
            this._bntLoginNotice.name = "bntLoginNotice";
            this._bntAchievement1 = UIFactory.gLoadedButton(ImagesConst.rt_achieve1_upSkin, this.iconWidth * 1, this.iconHeight * 1, 42, 42, this);
            this._bntAchievement1.name = "achievement";
            this._signUp = UIFactory.gLoadedButton(ImagesConst.rt_signin_upSkin, this.iconWidth * 0, this.iconHeight * 1, 42, 42, this);
            this._signUp.name = "signUp";
            this._line2 = [this._bntLoginNotice, this._bntAchievement1, this._signUp, this._btnMarket];
            this._levelOpenObj2 = {bntLoginNotice:36, achievement:GameConst.AchievementOpenLevel, signUp:999, btnMarket:GameDefConfig.instance.getSystemOpenLevel(15), halidom:GameDefConfig.instance.getSystemOpenLevel(10)};
            this.addEventListener(MouseEvent.CLICK, this.openWinHandeler);
            this._netWork = UICompomentPool.getUICompoment(NetWorkStatePanel) as NetWorkStatePanel;
            addChild(this._netWork);
            this._netWork.x = 80;
            this._netWork.y = -50;
            this.checkOpenLevel();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._line2 = null;
            this._levelOpenObj2 = null;
            this._btnMarket.dispose(param1);
            this._bntLoginNotice.dispose(param1);
            this._bntAchievement1.dispose(param1);
            this._bntRank.dispose(param1);
            this._netWork.dispose(param1);
            this._signUp.dispose(param1);
            this._bntLoginNotice = null;
            this._bntAchievement1 = null;
            this._btnMarket = null;
            this._bntRank = null;
            this._netWork = null;
            this._signUp = null;
            this.removeEventListener(MouseEvent.CLICK, this.openWinHandeler);
            return;
        }// end function

        private function openWinHandeler(event:MouseEvent) : void
        {
            var _loc_2:* = event.target;
            switch(_loc_2)
            {
                case this._btnMarket:
                {
                    GameManager.instance.popupModuleType(ModuleType.Market);
                    break;
                }
                case this._bntAchievement1:
                {
                    GameManager.instance.popupModuleType(ModuleType.Achievement);
                    break;
                }
                case this._bntRank:
                {
                    GameManager.instance.popupModuleType(ModuleType.Ranking);
                    break;
                }
                case this._bntLoginNotice:
                {
                    GameManager.instance.popupModuleType(ModuleType.LoginNotice);
                    break;
                }
                case this._signUp:
                {
                    GameManager.instance.popupModuleType(ModuleType.SignUp);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function get netWorkPanel() : NetWorkStatePanel
        {
            return this._netWork;
        }// end function

        private function layout() : void
        {
            var _loc_4:GLoadedButton = null;
            var _loc_1:* = this.iconWidth * 2;
            var _loc_2:int = 0;
            var _loc_3:* = this._line2.length - 1;
            while (_loc_3 >= 0)
            {
                
                _loc_4 = this._line2[_loc_3];
                if (_loc_4 && _loc_4.visible)
                {
                    _loc_4.x = _loc_1 - _loc_2 * this.iconWidth;
                    _loc_2++;
                }
                _loc_3 = _loc_3 - 1;
            }
            return;
        }// end function

        public function checkOpenLevel() : void
        {
            var _loc_3:GLoadedButton = null;
            var _loc_4:int = 0;
            var _loc_1:* = Cache.instance.role.entityInfo.level;
            var _loc_2:* = this._line2.length - 1;
            while (_loc_2 >= 0)
            {
                
                _loc_3 = this._line2[_loc_2];
                _loc_4 = int(this._levelOpenObj2[_loc_3.name]);
                if (_loc_3)
                {
                    if (_loc_1 >= _loc_4)
                    {
                        _loc_3.visible = true;
                    }
                    else
                    {
                        _loc_3.visible = false;
                    }
                }
                _loc_2 = _loc_2 - 1;
            }
            if (_loc_1 >= GameConst.RankOpenLevel)
            {
                this._bntRank.visible = true;
            }
            else
            {
                this._bntRank.visible = false;
            }
            this.layout();
            return;
        }// end function

        public function blinkBtn(param1:String, param2:Boolean) : void
        {
            if (param1 == null)
            {
                return;
            }
            var _loc_3:* = this.getChildByName(param1) as GLoadedButton;
            if (_loc_3)
            {
                if (param2)
                {
                    EffectManager.glowFilterReg(_loc_3, [FilterConst.chatTipsFilter], 2, 20, 2, 0);
                }
                else
                {
                    EffectManager.glowFilterUnReg(_loc_3);
                }
            }
            return;
        }// end function

    }
}
